package com.lxd;

import com.lxd.vo.tt;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class springamqptest {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    //直接发到队列
    @Test
    public void testSimpleQueue() {
        // 队列名称
        String queueName =  "hello-queue";
        // 消息
        String message = "hello, spring amqp222!";
        // 发送消息
        rabbitTemplate.convertAndSend(queueName, message);
    }
    //循环发送
    @Test
    public void testWorkQueue() throws InterruptedException {
        String queueName = "hello-queue";
        String message = "hello, spring web!";
        for (int i = 0; i < 50; i++) {
            rabbitTemplate.convertAndSend(queueName, message);
        }
    }

    //fanout 广播
    @Test
    public void testFanoutExchange() {
        String exchangeName = "testfanout1";
        String message = "hello, spring amqp!";
        rabbitTemplate.convertAndSend(exchangeName, "", message);
    }
    //Direct定向
    @Test
    public void testDirectExchange() {
        String exchangeName = "testdirectqueue";
        String message = "hello, spring amqp!!";
        tt tt = new tt();
        tt.setAge(12);
        tt.setName("xld");
        rabbitTemplate.convertAndSend(exchangeName, "red", tt);
        rabbitTemplate.convertAndSend(exchangeName, "blue", tt);
    }

    @Test
    public void testDirectExchange2() {

    }

}
